package com.ynet.hmds28.merchant.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.boot.hsf.annotation.HSFProvider;
import com.ynet.hm.merchant.domain.AirindexBean;
import com.ynet.hm.merchant.service.QueryAirService;
import com.ynet.hm.utils.UuidUtil;
import com.ynet.hmds28.merchant.dao.AirindexDao;
import com.ynet.hmds28.merchant.dao.ServiceflowDao;
import com.ynet.hmds28.merchant.model.Airindex;
import com.ynet.hmds28.merchant.model.Serviceflow;
@Transactional
@HSFProvider(serviceInterface = QueryAirService.class, serviceVersion = "1.0.0",serviceGroup = "hmds28")
public class QueryAirServiceImpl implements QueryAirService{
	@Autowired
	private AirindexDao airindexDao;
	@Autowired
	private ServiceflowDao serviceflowDao;
	
	@Override
	public AirindexBean queryAir(String merchantNo,String cityNum) {
		
		//TODO 记录流水,开启GTS事务
		serviceflowDao.enableTXC();
		
		Serviceflow sf = new Serviceflow();
		sf.setServiceflowid(UuidUtil.getUUid());
		sf.setServiceconsumeid(merchantNo);
		sf.setCalltime(new Date());
		serviceflowDao.insert(sf);
		
		Airindex air=airindexDao.selectByPrimaryKey(cityNum);
		AirindexBean airbean = new AirindexBean();
		if(air==null){
			airbean.setRemark("此城市暂未开通");
//			throw new MyException(ExceptionEnum.AIRCITY_IS_NULL);
		}else{
			airbean.setAirpressure(air.getAirpressure());
			airbean.setAirquality(air.getAirquality());
			airbean.setCarbonmono(air.getCarbonmono());
			airbean.setCityname(air.getCityname());
			airbean.setCitynum(air.getCitynum());
			airbean.setHumidity(air.getHumidity());
			airbean.setNdio(air.getNdio());
			airbean.setOzone(air.getOzone());
			airbean.setParticulate(air.getParticulate());
			airbean.setPm(air.getPm());
			airbean.setRemark(air.getRemark());
			airbean.setSulfurdio(air.getSulfurdio());
			airbean.setWind(air.getWind());
		}
		return airbean;
	}

}
